<%@ page contentType="text/html; charset=utf-8" language="java"%>
<%@ include file="/common/index.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>系统用户</title>
<link type="text/css" rel="stylesheet" href="<%=basePath %>/css/index.css" />
<script language="javascript" src="<%=basePath %>/js/jquery-1.7.1.min.js"></script>
<script language="javascript" src="<%=basePath %>/js/lightbox/jquery.lightbox_me.js"></script>
<script language="javascript" src="<%=basePath %>/js/validate.js"></script>
<script language="javascript" src="<%=basePath%>/js/jquery.form.js" /></script>
<script language="javascript" type="text/javascript" src="<%=basePath%>/js/My97DatePicker/WdatePicker.js"></script>


</head>
<body>
        <div class="right_main">
        	<div class="right_title"></div> 
            <div class="right_main_title_bg">
            	<s:form id="selectForm"  action="/manager/batchGame/select.shtml" theme="simple">  
					<div class="right_main_padding_1">
						<span class="spanTxt">游戏：</span>
                        <s:select name="vo.gameName" list="#{'':'选择','征途':'征途','征途2':'征途2','大主宰':'大主宰','鲁塔':'鲁塔'}"></s:select>
                        <span class="spanTxt">礼包类别：</span>
                        <s:select name="vo.fuliType" list="#{'':'选择','1':'激活码','2':'礼包','3':'道具','4':'周边'}"></s:select>
	                	&nbsp;&nbsp;&nbsp;&nbsp;
	                    <span class="btn_1 searchBtn"  id="selectButton" onclick="selectData();" ></span>
	                    &nbsp;&nbsp;&nbsp;&nbsp;<span class="default_btn_2" onclick="javascript:toImportDiv();">导入游戏礼包</span>
	                    <span style="display: none"> 
							gotoPage<s:textfield name="gotoPage" id="gotoPage" /> 
							pageSize<s:textfield name="pageSize" id="pageSize" /> 
							firstPage<s:textfield name="firstPage" id="firstPage" /> 
							lastPage<s:textfield name="lastPage" id="lastPage" />
							nextPage<s:textfield name="nextPage" id="nextPage" />
							prePage<s:textfield name="prePage" id="prePage" /> 
							countPage<s:textfield name="countPage" id="countPage" />
							countData<s:textfield name="countData" id="countData" />
						</span>
                </div>
			    </s:form>
                <table class="table_1" cellpadding="0" cellspacing="1">
                	<tr class="th_bg">
                	 	<td>游戏名</td>
                	 	<td>类型</td>
                        <td>标题</td>
                        <!-- 
                        <td>图片</td>
                        <td>描述</td> -->
                        <td>礼包总数</td>
                        <td>剩余总数</td>
                        <td>开始时间</td>
                        <td>结束时间</td>
                        <td>状态</td>
                        <td>操作</td>
                    </tr>
                 <s:iterator value="dataList" status="st">  
                 	<s:if test="#st.odd==true">
                 		<tr class="tr_1">
                 	</s:if>
                 	<s:else>
                 		<tr class="tr_2">
                 	</s:else>
                        <td><s:property value="gameName"/></td>
                        <td><s:if test="fuliType==1">激活码</s:if><s:elseif test="fuliType==2">礼包</s:elseif><s:elseif test="fuliType==3">道具</s:elseif><s:elseif test="fuliType==4">周边</s:elseif></td>
                        <td><s:property value="title"/></td>
                        <!-- 
                         <td><s:property value="imgSrc"/></td>
                        <td><s:property value="descStr"/></td>
                         -->
                        <td><s:property value="ncount"/></td>
                        <td><s:property value="ncount-useCount"/></td>
                        <td><s:date name="starttime"/></td>
                        <td><s:date name="endtime"/></td>
                        <td><s:if test="state==1">编辑中</s:if><s:elseif test="state==2"><font color="blue">已上架</font></s:elseif><s:elseif test="state==3"><font color="red">已下架</font></s:elseif></td>
                        <td>
                        	<s:if test="state==1">
                        		<span class="shouxing" onclick="deleteVo('<s:property value="id"/>','<s:property value="batchCode"/>')"> 删除 |</span>
                        	</s:if>
                        	<span class="shouxing" onclick="toUpdateDiv('<s:property value="id"/>')"> 设置</span>
                        	
                        	<s:if test="state==2">
                        		|<span class="shouxing" onclick="toUpdateState('<s:property value="id"/>',3,'<s:property value="title"/>')"> 下架</span>
                        	</s:if>
                        	<s:else>
                        		|<span class="shouxing" onclick="toUpdateState('<s:property value="id"/>',2,'<s:property value="title"/>')"> 上架</span>
                        	</s:else>
                        	
                        	|<span class="shouxing"   onclick="openPage('<%=basePath %>/manager/batchGame/selectGameCodeList.shtml?batchCode=<s:property value="batchCode"/>');">礼包列表</span>
                        </td>
                 	</tr>
				 </s:iterator>                    
                </table>
                <div class="page_div">
                    共 <span id="allcount"><s:property value="countData"/></span> 条记录 &nbsp;	每页 <span id="pagesize" ><s:property value="pageSize"/></span> 条记录&nbsp;
					共 <span id="pagecount" ><s:property value="countPage"/></span> 页&nbsp;
					第 <span id="pageno" ><s:property value="gotoPage"/></span> 页&nbsp;&nbsp;
					<input type="button" class="wbt" value="首页" onclick="if(g('gotoPage').value!=g('firstPage').value){g('gotoPage').value=g('firstPage').value;selectData();}else{alert('已经在首页');}"/>
					&nbsp;
					<input type="button" class="wbt" value="上一页" onclick="if(g('gotoPage').value!=g('firstPage').value){g('gotoPage').value=g('prePage').value;selectData();}else{alert('已经在首页');}" />
					&nbsp;
					<input type="button" class="wbt" value="下一页" onclick="if(g('gotoPage').value != g('countPage').value){g('gotoPage').value=g('nextPage').value;selectData();}else{alert('已经在末页');}" />
					&nbsp;
					<input type="button" class="wbt" value="末页" onclick="if(g('gotoPage').value != g('lastPage').value){g('gotoPage').value=g('lastPage').value;selectData();}else{alert('已经在末页');}" />
					&nbsp;&nbsp;
                    跳转到&nbsp;<input type="text"  name="pageNum" id="pageNum" style="width: 30px;"   />&nbsp;页 &nbsp;&nbsp; <input type="button"   onclick="gotoThePage()"    value="确定"   />
            	</div>
            </div>
        </div>



<div id="SHOW_DIV_1" style="height:1000px;display:none;overflow:auto;">
        <div class="show_main">
            <div class="title">编辑游戏礼包信息</div>
            <div class="content">
              <s:form id="insert-update-Form" name="insert-update-Form"  theme="simple"  enctype ="multipart/form-data" method="post">
              	<input type="hidden" class="inputText_1" name="id" id="id" value="" />
                <ul>
                    <li>
                        <span class="spanTxt">标题：</span>
                        <input type="text" class="inputText_1" name="title"  id="title_1"  value=""  maxlength="20"  />
                    </li>
                     
                    <li>
                    	<span class="spanTxt">开始时间：</span>
                    	<input type="text" class="inputText_1" name="starttime1"  id="starttime_1"  value=""    onclick="WdatePicker({isShowClear:false,readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})" />
                        <span class="spanTxt">结束时间：</span>
                        <input type="text" class="inputText_1" name="endtime1"    id="endtime_1"  value=""   onclick="WdatePicker({isShowClear:false,readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})" />
                        </select>
                    </li>
                     <li>
                        <span class="spanTxt">描述：</span>
                        <textarea rows="5" cols="60"  name="descStr"  id="descStr_1"></textarea>
                    </li>
                    <br><br><br><br><br><br><br><br><br><br><br><br>
                     <li>
                    	<span class="spanTxt">图片：</span>
                        <s:file name="gameImg" id="gameImg" accept="image/*"></s:file>
                        
                        <span class="spanTxt"></span>
                        <img src="" name="imgSrc"  height="100" width="100"  /> 
                        <s:hidden name="hasImg" id="hasImg" value="0"></s:hidden>
                    </li>
                    <li></li>
                    <li></li>
                    <li></li>
                </ul>
      			</s:form>
            </div>
            <div class="bottom">
                <span class="default_btn_1" id="insert-update-but"  onclick="update();"   >确定</span>&nbsp;&nbsp;&nbsp;&nbsp;
                <span class="default_btn_1 close">取消</span>
            </div>
        </div>
	</div>
	
	<div id="SHOW_DIV_2" style="height:600px;display:none;overflow:auto;">
        <div class="show_main">
            <div class="title">导入游戏礼包</div>
            <div class="content">
              <s:form id="insert-update-Form-2" name="insert-update-Form-2"  theme="simple" enctype ="multipart/form-data" method="post">  
                <ul>
                    <li>
                        <span class="spanTxt">游戏列表：</span>
                        <select name="gameName" id="vo.status">
                         	<option value="征途">征途</option>
                         	<option value="征途2">征途2</option>
                         	<option value="大主宰">大主宰</option>
                         	<option value="鲁塔">鲁塔</option>
                        </select>
                        <span class="spanTxt">福利类别：</span>
                        <select name="fuliType" id="vo.status">
                         	<option value="1">激活码</option>
                         	<option value="2">禁用</option>
                         	<option value="3">道具</option>
                         	<option value="4">周边</option>
                        </select>
                    </li>
                     <li>
                    	<span class="spanTxt"> </span>只支持excel97到2003版本的excel 
                    </li>
                     <li>
                    	<span class="spanTxt">导入Excel：
                    	</span>
                    	<span class="spanTxt"></span>
                    	<s:file name="excel" accept="excel/*"  ></s:file>
                    	
                    </li>
                </ul>
      			</s:form>
            </div>
            <div class="bottom">
                <span class="default_btn_1" id="insert-update-but-2"  onclick="doImport();"   >确定</span>&nbsp;&nbsp;&nbsp;&nbsp;
                <span class="default_btn_1 close">取消</span>
            </div>
        </div>
	</div>
	
<script language="javascript">

	$(function(){
		
		$('.close_but').live('click',function(){
			$(this).parent().remove();
		});
		
	})


	 function selectData()
	 {	
	 	$("#selectForm").submit();
	 }

	function toImportDiv(){
		$("#SHOW_DIV_2").lightbox_me({
			 centered: false
			,modalCSS:{}
			,onClose:function(){clearFormValue('insert-update-Form-2');}
		});
		$('#insert-update-but-2').attr("onclick","doImport();");
	}
	
	
	
	function doImport(){

		var url = "<%=basePath %>/manager/batchGame/importGameData.shtml";
	
		var options = {
				dataType:"html",
				success: callbackImportExcel
			};
		$('#insert-update-Form-2').attr('action',url);
		$('#insert-update-Form-2').ajaxSubmit(options);
		
	}
	
	
	function callbackImportExcel(m){
		rs = eval('('+m+')');
		if(rs.code==0){
			alert('上传成功');
			selectData();
		}else{
			alert(rs.info);
		}
		return;
	}
	

	function toUpdateDiv(id){
		
		$("#SHOW_DIV_1").lightbox_me({
			centered: false
			,modalCSS:{top:'20px'}
			,onLoad:function(){
				var url = "<%=basePath %>/manager/batchGame/selectVoById.shtml";
				var param = {id:id};
				$.post(url 
					,param 
						,function(rs) {
							if(rs.code==0){
								fillTemplateValue("insert-update-Form",rs.data);
							}
						}
				   ,'json');
			}
			,onClose:function(){clearFormValue('insert-update-Form');}
		});
	}
	

	function update(){
	
		
		if(! checkParas() ){
			return;
		}
		
		var url = "<%=basePath %>/manager/batchGame/setGameInfo.shtml";
	
		var options = {
				dataType:"html",
				success: callbackSetGameInfo
			};
		$('#insert-update-Form').attr('action',url);
		$('#insert-update-Form').ajaxSubmit(options);
		
	}
	
	
	function callbackSetGameInfo(m){
		rs = eval('('+m+')');
		if(rs.code==0){
			alert('操作成功');
			selectData();
		}else{
			alert(rs.info);
		}
		return;
	}
	
	
	function checkParas(){
		if($('#title_1').val()==''){
			alert('请输入标题');	
			return false;
		}
		if($('#starttime_1').val()==''){
			alert('请输入开始时间');	
			return false;
		}
		if($('#endtime_1').val()==''){
			alert('请输入结束时间');	
			return false;
		}
		
		if($('#descStr_1').val()==''){
			alert('请输入描述');	
			return false;
		}
		
		if($('#hasImg').val()!='1'){
			if($('#gameImg').val()==null || $('#gameImg').val()=='' ){
				alert('请上传图片');
				return;
			}
		}else{
			if($('#gameImg').val()!=null && $('#gameImg').val()!='' ){
				$('#hasImg').val('0');  //覆盖原图片
			}
		}
		
		return true;
	}
	
	function fillTemplateValue(boxId,json){
		var keys = new Array("id","title","descStr","starttime1","endtime1","imgSrc" ); //这个要自定义
		
		for(var i=0;i<keys.length;i++){
			var e1 = $("#insert-update-Form [name*="+keys[i]+"]");
			if(e1.prop("nodeName")=="TEXTAREA"){
				e1.html(json[keys[i]]);
			}else if(e1.prop("nodeName")=="INPUT" || e1.prop("nodeName")=="SELECT" ){
				e1.val(json[keys[i]]);
			}else if(e1.prop("nodeName")=="IMG" ){
				e1.attr("src",json[keys[i]]);
				$('#hasImg').val('1');		
			}
		}
	
		$('#insert-update-but').attr("onclick","update();");
	}
	

	function clearFormValue(fId){
		$('#'+fId)[0].reset();
		$('#'+fId).find('textarea').html('');
	}
	
	function deleteVo(id,batchCode){
		var url = "<%=basePath %>/manager/batchGame/delete.shtml";
		var param = {id:id,batchCode:batchCode};
		$.post(url 
			,param 
				,function(rs) {
					if(rs.code==0){
						selectData();
					}
				}
		   ,'json');
	}
	


	function toUpdateState(id,st,title){
		if(title==null || title==''){
			alert('资料不完整,不允许上下架');
			return;
		}
		var url = "<%=basePath %>/manager/batchGame/toUpdateState.shtml";
		var param = {id:id,st:st};
		$.post(url 
			,param 
				,function(rs) {
					if(rs.code==0){
						alert('操作成功');
						selectData();
					}
				}
		   ,'json');
	}

	
	function openPage(url){
		window.open(url,'newwindow','height=500,width=576,top=200,left=350,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no') ;
	}
	
	
	function gotoThePage(){
		
		var p = $('#pageNum').val();
		if(p>$('#countPage').val()){
			p = $('#countPage').val();
		}
		else if(p<1){
			p = 1;
		}
		$('#gotoPage').val(p);
		selectData();
	}
	
	

</script>    
</body>
</html>
